<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="box1"></div>
    <div id="box2"></div>
    <div id="box3"></div>

    <script>

        //第一种方法，直接使用setAttribute方法设置样式
        var box1 = document.getElementById("box1");
        box1.setAttribute("style","width:100px;height:100px;background:red");

        //第二种方法，元素节点的style属性
        var box2 = document.getElementById("box2");
        box2.style.width="100px";
        box2.style.height="100px";
        box2.style.backgroundColor="green";

        //第三种方法，cssText属性
        var box3 = document.getElementById("box3");
        box3.style.cssText = "width:100px;height:100px;background:blue";

    </script>
</body>
</html>